import { getcommunity, getuser } from "../../utils/api"
import '../../utils/lodash_fix'
let _ = require("../../utils/lodash.min");
Page({
  /**
   * 页面的初始数据
   */
  data: {
    select: false,
    grade_name: {},
    grades: [
      '北京市',
      '深圳市',
      '上海市',
      '广州市',
    ]
  },
  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {
    this.getuser()
  },
  getuser() {
    getuser().then(res => {
      if (_.isEqual(res.statusCode, 200)) {
        let comid = res.data.data.default_community_uuid
        wx.setStorageSync('user', res.data.data)
        getcommunity().then(ress => {
          let arr = ress.data.data
          let a = ''
          arr.forEach(e => {
            if (e.uuid === comid) {
              a = e
            }
          })
          if (_.isEqual(a, '')) {
            wx.navigateTo({ url: '/pages/binding/binding?first=' + true })
          } else {
            this.setData({ grade_name: a, grades: arr })
          }
        })
      } else {
        wx.navigateTo({
          url: '/pages/login/login',
        })
      }
    })
  },
  topay() {
    wx.switchTab({
      url: '/pages/pay/pay',
    })
  },
  bindShowMsg() {
    this.setData({
      select: !this.data.select
    })
  },
  /**
   * 已选下拉框
   */
  mySelect(e) {
    console.log(e)
    var name = e.currentTarget.dataset.name
    this.setData({
      grade_name: name,
      select: false
    })
  },
  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  }
})